package com.gragra.sampling.vector.tests;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import com.gragra.data.MixingCorpus;
import com.gragra.data.MixingCorpusBaseImplementation;
import com.gragra.sampling.ThreadedUniformAccess;
import com.gragra.sampling.vector.LimitedClassesUnitCRP;
import com.gragra.sampling.vector.LimitedClassesUnitCRPFactory;
import com.gragra.sampling.vector.VectorStructure;
import com.gragra.util.StringToInt;
/**
 * 
 * @author Christoph Teichmann
 * 14.10.2013
 */
public class TestLimitedClassesUnitCRP
{
	/**
	 * 
	 */
	private ThreadedUniformAccess tua;
	/**
	 * 
	 */
	private LimitedClassesUnitCRP lcc;
	/**
	 * 
	 */
	private VectorStructure vs1;
	@Before
	public void setUp() throws Exception
	{
		vs1 = new VectorStructure(StringToInt.ensure("Hans"), new double[] {5.0,4.5,7.2,2.1}, new int[][] {{0,0},{1,0},{1,1},{2,3}}, 3);
		LimitedClassesUnitCRPFactory fact = new LimitedClassesUnitCRPFactory(5, 0.1, 0.5, 3);
		MixingCorpus<VectorStructure> corpus = new MixingCorpusBaseImplementation<VectorStructure>();
		corpus.addData(vs1);
		lcc = (LimitedClassesUnitCRP) fact.createNewInstance(corpus);
		tua = new ThreadedUniformAccess(3);
	}
	@Test
	public void test()
	{
		vs1.setLabel(0, 0);
		double prob = lcc.makeLogProb(vs1, 0);
		lcc.add(vs1, 0);
		lcc.add(vs1, 0);
		lcc.add(vs1, 0);
		lcc.add(vs1, 0);
		assertTrue(lcc.makeLogProb(vs1, 0) > prob);
		lcc.remove(vs1, 0);
		lcc.remove(vs1, 0);
		lcc.remove(vs1, 0);
		lcc.remove(vs1, 0);
		assertEquals(prob,lcc.makeLogProb(vs1, 0),0.0);
		vs1.initialize(lcc, tua);
	}
}